package com.huiruan.controller.pc;

import com.huiruan.dto.LoginDTO;
import com.huiruan.dto.WxLoginDTO;
import com.huiruan.service.AuthService;
import com.huiruan.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 认证控制器
 */
@RestController
@RequestMapping("/pc/auth")
public class AuthController {
    private final AuthService authService;



    @Autowired
    public AuthController(AuthService authService) {
        this.authService = authService;
    }

    /**
     * 生成验证码
     */
    @GetMapping("/captcha")
    public Result<?> generateCaptcha() {
        return authService.generateCaptcha();
    }

    /**
     * PC端登录
     */
    @PostMapping("/login")
    public Result<?> login(@Validated @RequestBody LoginDTO loginDTO) {
        return authService.login(loginDTO);
    }

    /**
     * 微信小程序登录
     */
    @PostMapping("/wxLogin")
    public Result<?> wxLogin(@Validated @RequestBody WxLoginDTO wxLoginDTO) {
        return authService.wxLogin(wxLoginDTO);
    }


//    @PostMapping("/logout")
//    public Result<?> logout() {
//        return Result.success( "退出成功");
//    }
//
//    @GetMapping("getRouters")
//    public Result getRouters()
//    {
//        SysUser user = JwtUtil.getPcUserInfo();
//        Long userId = user.getId();
////
////        List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId);
//        return Result.success(menuService.buildMenus(menus));
//    }
}
